feat(web): resolve Anthropic thinking config from model capabilities#1294
Conversation
Determine adaptive vs. extended thinking by querying the Anthropic Models API for the model's capabilities, instead of maintaining a hardcoded allowlist of model IDs that drifts with each release. Cached per model; falls back to omitting the thinking option when the lookup fails. Adds @anthropic-ai/sdk for the typed models.retrieve call. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughReplaces hardcoded Anthropic model-id checks with a dynamic resolver that queries the Anthropic Models API for supported "thinking" modes, adds the Anthropic SDK dependency, caches results, reports errors to Sentry, and updates the changelog. ChangesDynamic Anthropic Thinking Configuration
Sequence Diagram(s)sequenceDiagram
participant ProviderConfig as Anthropic ProviderConfig
participant Cache as InMemoryCache
participant Resolver as tryResolveAnthropicThinkingConfig
participant AnthropicClient as Anthropic SDK Client
participant ModelsAPI as Anthropic Models API
participant Sentry as Sentry
ProviderConfig->>Cache: check(baseUrl+modelId)
alt cache hit
Cache-->>ProviderConfig: return cached thinking config
else cache miss
ProviderConfig->>Resolver: call(baseUrl, modelId, apiKey, authToken, headers)
Resolver->>AnthropicClient: create client(normalized baseUrl, apiKey/auth)
Resolver->>ModelsAPI: models.retrieve(modelId) (10s timeout)
alt success & thinking supported
ModelsAPI-->>Resolver: capabilities
Resolver->>Cache: store result(baseUrl+modelId)
Resolver-->>ProviderConfig: return thinking config (adaptive|enabled)
else failure or unsupported
ModelsAPI-->>Resolver: error / missing capability
Resolver->>Sentry: captureException(error)
Resolver->>Resolver: logger.warn(...)
Resolver-->>ProviderConfig: return undefined
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/web/src/features/chat/llm.server.ts`:
- Around line 378-381: The cache only stores truthy thinking-config results so
models that return "no thinking support" repeatedly call
client.models.retrieve(...); modify the logic around
anthropicThinkingConfigCache and cacheKey to always set a cache entry (including
explicit negative/empty markers) after retrieving from
client.models.retrieve(modelId) so unsupported models are cached too, and
read/write that marker from anthropicThinkingConfigCache.get/set to avoid
repeated API calls.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 44402c0b-5cfd-4b09-b0b9-68eb3455e1a9
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (3)
CHANGELOG.mdpackages/web/package.jsonpackages/web/src/features/chat/llm.server.ts
License Audit
Weak Copyleft Packages (informational)
Resolved Packages (20)
|
Resolves the Anthropic
thinkingprovider option (adaptive vs. extended) by querying the Models API for the model's capabilities, instead of maintaining a hardcoded allowlist of model IDs that drifts out of date with each release.{ type: "adaptive" }; older models fall back to{ type: "enabled", budgetTokens }; the option is omitted entirely if the model doesn't support thinking or the lookup fails.(baseUrl, model)to avoid an extra request per call.@anthropic-ai/sdkfor the typedmodels.retrievecall.🤖 Generated with Claude Code
Summary by CodeRabbit